package ua.pp.bizon.cripto.configuration;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ua.pp.bizon.cripto.authorization.UI;

public class ConfigurationFactory {
    
    private Configuration configuration;
    private UI ui;
    public UI getUi() {
        return ui;
    }

    public void setUi(UI ui) {
        this.ui = ui;
    }
    private Log log = LogFactory.getLog(getClass());
    
    
    public void configure(String args[]){
        if (args.length > 0) {
            configuration = Configuration.load(args);
        } else {
            try {
                configuration = Configuration.load("config.properties");
            } catch (IOException e) {
                log.warn(e.getMessage(), e);
            }
        }
        if (configuration == null || configuration.getFrom() == null || configuration.getDirection() == null || configuration.getTo() == null){
            configuration = ui.configure(configuration);
        }
    }
    
    public Configuration getConfiguration() {
        return configuration;
    }
    public void setConfiguration(Configuration configuration) {
        this.configuration = configuration;
    }

}
